# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=pt2-clone
pkgver=1.64
pkgrel=1
pkgdesc='A highly accurate clone of the classic ProTracker 2.3D software for Amiga'
arch=('loong64' 'x86_64') # note: not compatible with big-endian CPUs
url='https://16-bits.org/pt2.php'
license=('BSD')
depends=('glibc' 'alsa-lib' 'sdl2' 'hicolor-icon-theme')
makedepends=('git' 'cmake')
install='pt2-clone.install'
_commit='baeb7922a78544973f68d1df1c7d71a00bf98d1a'
source=("$pkgname::git+https://github.com/8bitbubsy/pt2-clone#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # modify desktop file
  sed \
    -e 's/Icon.*/Icon=pt2-clone/' \
    -e 's/Comment.*/Comment = Chiptune Tracker/' \
    -i "release/other/Freedesktop.org Resources/ProTracker 2 clone.desktop"
}

build() {
  cmake \
    -S "$pkgname" \
    -B build \
    -DCMAKE_BUILD_TYPE='None' \
    -DCMAKE_INSTALL_PREFIX='/usr' \
    -Wno-dev

  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  cd "$pkgname"

  # desktop file
  install -vDm644 \
    "release/other/Freedesktop.org Resources/ProTracker 2 clone.desktop" \
    "$pkgdir/usr/share/applications/$pkgname.desktop"

  # application icon
  install -vDm644 \
    "release/other/Freedesktop.org Resources/ProTracker 2 clone.png" \
    "$pkgdir/usr/share/icons/hicolor/512x512/apps/$pkgname.png"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md release/*.txt release/other/protracker.ini

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE*
  install -vDm644 "release/other/Freedesktop.org Resources/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE.freedesktop-resources"
}
